package com.sinog.front.controller.curl;

import com.sinog.core.utilbean.Constants;
import com.sinog.core.utilbean.Result;
import com.sinog.core.utilbean.ReturnCode;
import com.sinog.front.feign.biz.DataToRedisService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;

/**
 * @desc 缓存一些字典数据到redis
 * @author -
 * @date -
 */
@RestController
@Api(tags = "1、缓存字典数据到redis")
public class DataToRedisController {

    @Resource
    private DataToRedisService dataToRedisService;

    /**
     * 全国行政区划编码名称 - areaCode
     * @return Result
     */
    @ApiImplicitParams({})
    @ApiOperation(value = "初始化全部缓存😊", notes = "点一下就行哦😯")
    @RequestMapping(value = "/redis/api/azbj/initAllRedisCache", method = RequestMethod.GET)
    public Result initAllRedisCache() {
        try {
            //初始化全国机构编码及名称映射
            dataToRedisService.saveAreaCodeData();
            //初始化全国机构编码及父编码映射
            dataToRedisService.saveDataToRedisCodeParent();
            //初始化罪名编码及名称
            dataToRedisService.saveDataToRedisCritype("critypeCode", Constants.CodeType.CODE_ZMFL_DM);
            //初始化职业技能编码及名称
            dataToRedisService.saveDataToRedisCritype("jineng",Constants.CodeType.CODE_ZYJN);
            //初始化罪名名称及编码
            dataToRedisService.saveDataToRedisCritypeZn("critypeZn",Constants.CodeType.CODE_ZMFL_DM);
            //初始化罪名分类编码
            dataToRedisService.saveDataToRedisCritypeP("fzlx",Constants.CodeType.CODE_ZMFL_DM);
            //初始化捕前职业中文-编码
            dataToRedisService.saveDataToRedisBqzyZn("bqzyZn");
            //初始化捕前职业编码-中文
            dataToRedisService.saveDataToRedisBqzy("bqzy");
            //初始化罪名对应的顶级犯罪类型
            dataToRedisService.saveDataToRedisCritypeAndFzlx("critypeAndFzlx");
            //全省编码+名称
            dataToRedisService.saveDataToRedisProvince("province");
        } catch(RuntimeException e) {
            return Result.failure(ReturnCode.FAILURE);
        }
        return Result.success();
    }

    /**
     * 初始化行政区划 - pushTbsysCode
     * @return Result
     */
    @Deprecated
    @ApiImplicitParams({})
    @ApiOperation(value = "初始化行政区划", notes = "key:pushTbsysCode")
    @RequestMapping(value = "/redis/api/azbj/saveDataToRedisXzqh", method = RequestMethod.GET)
    public Result saveDataToRedisXzqh() {
        return dataToRedisService.saveDataToRedisXzqh("pushTbsysCode");
    }

    /**
     * 罪名对应的顶级犯罪类型 - critypeAndFzlx
     * @return Result
     */
    @Deprecated
    @ApiImplicitParams({})
    @ApiOperation(value = "罪名对应的顶级犯罪类型", notes = "key:critypeAndFzlx")
    @RequestMapping(value = "/redis/api/azbj/saveDataToRedisCritypeAndFzlx", method = RequestMethod.GET)
    public Result saveDataToRedisCritypeAndFzlx() {
        return dataToRedisService.saveDataToRedisCritypeAndFzlx("critypeAndFzlx");
    }

    /**
     * 全国行政区划编码名称 - areaCode
     * @return Result
     */
    @Deprecated
    @ApiImplicitParams({})
    @ApiOperation(value = "全国行政区划编码名称", notes = "key:areaCode")
    @RequestMapping(value = "/redis/api/azbj/saveDataToRedis", method = RequestMethod.GET)
    public Result saveDataToRedis() {
        return dataToRedisService.saveAreaCodeData();
    }

    /**
     * 全国行政区划编码及父编码 - areaCodeAndPcode
     * @return Result
     */
    @Deprecated
    @ApiImplicitParams({})
    @ApiOperation(value = "全国行政区划编码及父编码", notes = "key:areaCodeAndPcode")
    @RequestMapping(value = "/redis/api/azbj/saveDataToRedis/codeParent", method = RequestMethod.GET)
    public Result saveDataToRedisCodeParent() {
        return dataToRedisService.saveDataToRedisCodeParent();
    }

    /**
     * 罪名编码critypeCode、职业技能jineng
     * select code_id codeId,code_name codeName from tbsys_code where code_type=#{type}
     * 罪名编码：critypeCode 2_12
     * 职业技能：jineng  4_1
     * @param keyName redis存储键
     * @param codeType 字典表tbsys_code的code_type
     * @return Result
     */
    @Deprecated
    @ApiImplicitParams({@ApiImplicitParam(paramType = "query", required = true, dataType = "String", name = "keyName", value = "redis存储键"),@ApiImplicitParam(paramType = "query", required = true, dataType = "String", name = "codeType", value = "字典表tbsys_code的code_type")})
    @ApiOperation(value = "罪名编码critypeCode、职业技能jineng", notes = "罪名编码：critypeCode 2_12。职业技能：jineng  4_1")
    @RequestMapping(value = "/redis/api/azbj/saveDataToRedis/critype", method = RequestMethod.GET)
    public Result saveDataToRedisCritype(@RequestParam String keyName,@RequestParam String codeType) {
        return dataToRedisService.saveDataToRedisCritype(keyName,codeType);
    }

    /**
     * 罪名编码中文critypeZn
     * select code_name codeName,code_id codeId from tbsys_code where code_type=#{type}
     * 罪名编码：critypeZn 2_12
     * @param keyName redis存储键
     * @param codeType 字典表tbsys_code的code_type
     * @return Result
     */
    @Deprecated
    @ApiImplicitParams({@ApiImplicitParam(paramType = "query", required = true, dataType = "String", name = "keyName", value = "redis存储键"),@ApiImplicitParam(paramType = "query", required = true, dataType = "String", name = "codeType", value = "字典表tbsys_code的code_type")})
    @ApiOperation(value = "罪名编码中文critypeZn", notes = "罪名编码中文：critypeZn 2_12")
    @RequestMapping(value = "/redis/api/azbj/saveDataToRedis/critypeZn", method = RequestMethod.GET)
    public Result saveDataToRedisCritypeZn(@RequestParam String keyName,@RequestParam String codeType) {
        return dataToRedisService.saveDataToRedisCritypeZn(keyName,codeType);
    }

    /**
     * 罪名分类编码fzlx
     * select code_id codeId,code_name codeName from tbsys_code where code_type=#{type} and pcode_id='-1'
     * 罪名分类编码：keyName：fzlx ，code_type：2_12
     * @param keyName redis存储键
     * @param codeType 字典表tbsys_code的code_type
     * @return Result
     */
    @Deprecated
    @ApiImplicitParams({@ApiImplicitParam(paramType = "query", required = true, dataType = "String", name = "keyName", value = "redis存储键"),@ApiImplicitParam(paramType = "query", required = true, dataType = "String", name = "codeType", value = "字典表tbsys_code的code_type")})
    @ApiOperation(value = "罪名分类编码fzlx", notes = "罪名分类编码：keyName：fzlx ，code_type：2_12")
    @RequestMapping(value = "/redis/api/azbj/saveDataToRedis/critypeP", method = RequestMethod.GET)
    public Result saveDataToRedisCritypeP(@RequestParam String keyName,@RequestParam String codeType) {
        return dataToRedisService.saveDataToRedisCritypeP(keyName,codeType);
    }

    /**
     * 缓存捕前职业bqzy 2_8 key中文value code - bqzyZn
     * @param keyName redis存储键
     * @return Result
     */
    @Deprecated
    @ApiImplicitParams(@ApiImplicitParam(paramType = "query", required = true, dataType = "String", name = "keyName", value = "redis存储键"))
    @ApiOperation(value = "捕前职业中文key", notes = "系统初始化redis数据 - 捕前职业中文key")
    @RequestMapping(value = "/redis/api/azbj/saveDataToRedis/bqzyZn", method = RequestMethod.GET)
    public Result saveDataToRedisBqzyZn(@RequestParam String keyName) {
        return dataToRedisService.saveDataToRedisBqzyZn(keyName);
    }

    /**
     * 缓存捕前职业bqzy 2_8 key code value中文 - bqzy
     * @param keyName redis存储键
     * @return Result
     */
    @Deprecated
    @ApiImplicitParams(@ApiImplicitParam(paramType = "query", required = true, dataType = "String", name = "keyName", value = "redis存储键"))
    @ApiOperation(value = "捕前职业code key", notes = "系统初始化redis数据 - 捕前职业code key")
    @RequestMapping(value = "/redis/api/azbj/saveDataToRedis/bqzy", method = RequestMethod.GET)
    public Result saveDataToRedisBqzy(@RequestParam String keyName) {
        return dataToRedisService.saveDataToRedisBqzy(keyName);
    }

    /**
     * 全省的编码和名称
     * @param keyName redis存储键
     * @return Result
     */
    @Deprecated
    @ApiImplicitParams(@ApiImplicitParam(paramType = "query", required = true, dataType = "String", name = "keyName", value = "redis存储键"))
    @ApiOperation(value = "全省编码+名称", notes = "系统初始化redis数据 - 全省编码+名称")
    @RequestMapping(value = "/redis/api/azbj/saveDataToRedis/province", method = RequestMethod.GET)
    public Result saveDataToRedisProvince(@RequestParam String keyName) {
        return dataToRedisService.saveDataToRedisProvince(keyName);
    }
}